<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>设置资料</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/global.css}">
</head>
<body>

<div th:include="common/header::header"></div>

<div class="main fly-user-main layui-clear">
    <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="user">
        <li class="layui-nav-item layui-this">
            <a th:href="@{/user/set}">
                <i class="layui-icon">&#xe620;</i>
                基本设置
            </a>
        </li>
        <li class="layui-nav-item">
            <a th:href="@{/user/seticon}">
                <i class="layui-icon">&#xe620;</i>
                头像设置
            </a>
        </li>
        <li class="layui-nav-item">
            <a th:href="@{/user/setpsw}">
                <i class="layui-icon">&#xe620;</i>
                密码设置
            </a>
        </li>
        <li class="layui-nav-item">
            <a href="message.html">
                <i class="layui-icon">&#xe611;</i>
                我的消息
            </a>
        </li>
    </ul>
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab-content" style="padding: 20px 0;">
            <div class="layui-form layui-form-pane layui-tab-item layui-show">
                <form action="">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">昵称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_username" name="username" required lay-verify="required" autocomplete="off" value="" class="layui-input">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label for="L_sex" class="layui-form-label">性别</label>
                        <div class="layui-input-inline">
                            <input type="text" id="L_sex" name="sex" autocomplete="off" value="" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">请填入男/女</div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label for="L_sign" class="layui-form-label">签名</label>
                        <div class="layui-input-block">
                            <textarea placeholder="随便写些什么刷下存在感" id="L_sign"  name="signature" autocomplete="off" class="layui-textarea" style="height: 80px;"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" key="set-mine" lay-filter="*" lay-submit>确认修改</button>
                    </div>
                </form>
            </div>
    </div>
</div>
</div>

<div th:include="common/footer::footer"></div>

<script>
    layui.use(['form'],function () {
        var token = getCookie();
        var sexnumber;

        var form = layui.form,
            layer = layui.layer;

        form.on('submit(*)', function (data) {
//           layer.alert(data.field.username)

            var sex = data.field.sex;
            if (sex =="男"){
                sexnumber =0;
            }else if(sex=="女"){
                sexnumber =1;
            }else{
                layer.msg("性别输入错误",{icon:7});
                return false;
            };

            $.ajax({
                url:quark_user_update_api+token,
                type:'PUT',
                data:{
                    username:data.field.username,
                    signature:data.field.signature,
                    sex:sexnumber
                },
                success:function (data) {

                        if (data.status == 200) {
                            layer.msg("修改成功", {
                                icon: 1,
                                time: 1000 //1秒关闭
                            }, function(){
                                location.href = "/index";
                            });
                        } else if (data.status == 400) {
                            layer.msg(data.error, {icon: 7});
                        } else {
                            layer.msg(data.error, {icon: 5});
                        }
                    }

            },"json");
            return false;

        });
    })
</script>

</body>
</html>